package com.lyb.command.impl;

import com.lyb.Utils;
import com.lyb.command.AlpacaCommand;
import com.lyb.constant.DiskConstant;
import com.lyb.constant.SystemConstant;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * fdisk 命令处理类
 *
 * @author Mr.Alpaca
 * @version 1.4.0
 */
public class FdiskCommand implements AlpacaCommand {
    /**
     * 表示该类负责处理的命令
     */
    private static final String COMMAND = "fdisk";

    /**
     * 格式判断，输入语句需满足以下情况
     * 1.格式：{"fdisk"}
     * 2.没有参数
     *
     * @param input 用户输入的语句(已切分)
     * @return 判断结果
     */
    @Override
    public boolean formatJudge(String[] input) {
        /* 若输入语句有参数则错误 */
        return input.length == 1;
    }

    /**
     * 运行命令，调用相关函数输出操作结果
     *
     * @param command 命令语句
     */
    @Override
    public void go(String[] command) {
        long uniqueId = Utils.getUniqueId();
        Utils.outCommandResult("系统");
        Utils.outCommandResult("Alpaca System");
        Utils.outCommandResult("磁盘文件");
        Utils.outCommandResult("Disk " + SystemConstant.DISK_PATH + " " + DiskConstant.DISK_LENGTH / 1000 + "KB " + DiskConstant.DISK_LENGTH + "bytes");
        Utils.outCommandResult("磁块");
        Utils.outCommandResult("Blocks " + DiskConstant.BLOCKS_MAX_ASSOCIATION_NUM + " " + DiskConstant.DISK_LENGTH + "bytes");
        Utils.outCommandResult("启动引导分区 ");
        Utils.outCommandResult("Partition 1 Boot " + DiskConstant.DISKBLOCK_LENGTH);
        Utils.outCommandResult("I/O设备 ");
        Utils.outCommandResult("A " + " B " + " C");
        Utils.outCommandResult("磁盘文件类型: disk");
        Utils.outCommandResult("磁盘标识符: " + uniqueId);
        Utils.outCommandResult("Device \t Boot \t Blocks \t   Id   \t   \t     System ");
        Utils.outCommandResult("disk \t  * \t " + DiskConstant.DISK_LENGTH + " \t" + uniqueId + " \t Alpaca System");
        Utils.outCommandOver();
    }

    @Override
    public String getCommand() {
        return COMMAND;
    }
}
